package com.zr.jobs;

import com.zr.constant.RedisConstant;
import com.zr.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @auther zhaorui
 * @date 2019-11-26 - 19:35
 */
public class clearImgJob {

    @Autowired
    private JedisPool jedisPool;

    public void clearImg(){
        //获取Redis中 上传图片和确定两种集合的差值集合
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        //遍历集合 得到每个图片名称
        for (String picName : sdiff) {
            //在七牛云中删除对应名称的图片
            QiniuUtils.deleteFileFromQiniu(picName);
            //在 Redis中删除 对应图片名称
            jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,picName);
        }
    }

}
